/**
 * 功能描述 导航栏
 */

define(function (require, exports, module) {
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper");
	var i18n = require("i18n");
	var destinationfile = require("../store/destinationfile");
    var instance = {
        initComponent: function (params, widget) {
        	var subnav=new Subnav({
        		parentNode:".J-subnav",
				model : {
					title:i18n.get("destination_name", "目的地档案"),
					items : [{
						id : "search",
						type : "search",
						placeholder:"目的地名称",
						handler : function(str){
							var grid = widget.get("grid");
	                    		var obj={
		                   				s:str,
		                   				properties:"name",
	        	     					fetchProperties:destinationfile.fetchProperties
	                    		}
							aw.ajax({
								url:"api/destination/search",
								data:obj,
								dataType:"json",
								success:function(data){
									grid.setData(data);
								}
							});
						
						}
					},{
						id : "add",
						type : "button",
						text:"新增",		
						handler:function(){
							widget.get("form").reset();
							widget.show([".J-form"]).hide([".J-grid"]);
							$("#organization").attr("disabled","disabled")
							widget.get("subnav").hide(["add","search"]).show(["return"]);							
						}
					},{
						id : "return",
						type : "button",
						text:"返回",						
						show : false,
						handler:function(){
							widget.show([".J-grid"]).hide([".J-form"]);
							widget.get("subnav").hide(["return"]).show(["add","search"]);
							widget.get("grid").refresh();
						}
					}]
				}
        	});
        	widget.set("subnav",subnav);
        }
    };
    module.exports = instance;
});
